﻿@model PagedList<RBS.Core.Model.Hotel.H_Hotel_Seat>
<link href="~/Content/default/jiesuan.css" rel="stylesheet" />
<script src="~/Scripts/mustache.js"></script>
@using Webdiyer.WebControls.Mvc
@{
    ViewBag.Title = "座位信息表";
    Layout = "~/Views/Shared/_Layout.cshtml"; 


<script> 
    var o = new Object();
    var orderId = 0;
    var orderState = 0;
    var seatId = 0;
    var hotelId = 0;
    $(function () {
        $("#jiesuan").attr('disabled', 'true');
        $("#kaitai").attr('disabled', 'true'); 
        $("#jiesuan").click(function () {

            var url = "@Url.Action("jiesuan")?orderid=" + orderId; 
            window.location.href = url; 
        });
        $("#kaitai").click(function () { 
            var url = "@Url.Action("Kt")?seatId=" + seatId;
            window.location.href = url; 
           /* $.dialog({
                id: 'qx', lock: true, title: '顾客开台', width: '710px', height: '520px', content: "url:@@Url.Action("Kt")?seatId=" + seatId + "&HotelId=" + hotelId/*, ok: function () {
                                orderid = 123;
                                this.reload();
                                return false;
                                    }   #1#
            });*/
          }); 
    });
    //加载预定信息 
    function GetOrderList(seatId, hotelid, seateName) { 
        this.seatId = seatId;
        this.hotelId = hotelid;
        $("#seateName").html(seateName); 
        $("#jiesuan").attr('disabled', 'true');
        $("#OrderDetails").empty();
        $("#orderList1").empty();
        $("#Order").empty();
        var url = '@Url.Action("GetOrderList")?seatId=' + seatId + '&hotelid=' + hotelid;
        $.ajax({
            url: url,
            type: 'Post',
            dataType: 'json',
            success: function (result) { 
              
                if (result.Data.length == 0) {
                    $("#orderList1").html("<tr><td colspan=9 align='center'>暂时无人预定</td></tr>"); 
                    $('#kaitai').removeAttr('disabled');
                    return;
                } 
                //加载订单信息 
                GetOrder(result.Data[0]);  
                // 如果有菜单数据 则加载第一条数据
                GetOrderDetails(result.Data[0].Id, result.Data[0].OrderState);
                $.each(result.Data, function (index, row) {
                    var template = $('#OrderListTemp').html();
                    var bookData = Mustache.render(template, row);
                    $("#orderList1").append(bookData);
                });
            }
        });
    } 
    function GetOrder(order) {
        $("#Order").empty();
        var template = $('#OrderTemp').html();
        order.CreateTime=renderTime(order.CreateTime);
        var bookData = Mustache.render(template, order);
        $("#Order").append(bookData);
        
    }

    //加载菜单信息  
    function GetOrderDetails(orderid, orderState) {
        orderId = orderid;
        orderState = orderState; 
        if (orderId > 0 && orderState == 4) {
            $('#jiesuan').removeAttr('disabled');
            $("#kaitai").attr('disabled', 'true');

        } else {
           // $("#jiesuan").attr('disabled', 'true');
            $('#jiesuan').removeAttr('disabled');
        }
        var url = '@Url.Action("GetOrderDetails")?orderId=' + orderid;
        $.ajax({
            url: url,
            type: 'Post',
            dataType: 'json',
            success: function (result) {
                $("#OrderDetails").empty();
                if (result.Data.length == 0) {
                    return;
                }
                var numCount = 0;
                var priceCount = 0;
                var xiaoji = 0;
                $.each(result.Data, function (index, row) {
                    priceCount += row.Price * row.Num;
                    numCount += row.Num;
                    row.xiaoji = row.Price * row.Num;
                    var template = $('#OrderDetailsTemp').html(); //获取模版的html
                    var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                    $("#OrderDetails").append(bookData);
                });
                $("#priceCount").html(priceCount);
                //$("#numcount").html(numCount);
            }
        });
    }
    
    function renderTime(data) {
        var da = eval('new ' + data.replace('/', '', 'g').replace('/', '', 'g'));
        return da.getFullYear() + "年" + da.getMonth() + "月" + da.getDay() + "日" + da.getHours() + ":" + da.getSeconds();// + ":" + da.getMinutes();
    }
</script>
} 
<!--导航栏-->
@{
    @Html.Partial("_Location");
}
<!--/导航栏-->
<div class="line20">
</div>
<!--列表-->
<style> 
 
</style>
<div class="seat">
      <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected"> 座位列表</a></li>
                </ul>
            </div>
        </div>  
    <div id="seatList"> 
        @if (null != ViewData.Model)
        {
            foreach (var item in ViewData.Model)
            {
                <ul>
                    <li   onclick="GetOrderList(@item.Id,@item.HotelId,'@item.Name')">
                        <input id="hidId" type="hidden" value="@item.Id"/>
                        @*   @Html.DisplayFor(modelItem => item.RoomNumber)
                            @Html.DisplayFor(modelItem => item.Name)
                            @Html.DisplayFor(modelItem => item.Floor)
                            @Html.DisplayFor(modelItem => item.Category)
                            @Html.DisplayFor(modelItem => item.Numbers)
                         
                            @(item.AOBT==1?"是":"否") 
                            @Html.ActionLink("编辑", "HotelSeatEdit", new { id = item.Id, action = @RBS.Common.RBSEnums.ActionEnum.Edit })*@
                        <img src="../@item.Picture" />
                        <div >
                            @(item.Name)（@item.Numbers）人
                        </div>
                    </li>
                </ul>
            }
        }   
    </div>
       
    <div class="line20"></div>

    <div id="orderList" style="width: 100%">
          <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected"> 订单列表</a></li>
                </ul>
            </div>
          </div>  
          <div class="line5"></div>
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
            <tr>
                <th >订单ID</th>
                <th align="left">订单状态</th>
                <th align="left">订单渠道</th>
                <th align="left">联系人</th>
                <th align="left">用户手机</th>
                <th align="left">订单备注</th>
                <th align="left">预订吃饭日期</th>
                <th align="left">吃饭人数</th>
                <th width="8%">操作</th>
            </tr>
            <tbody id="orderList1"></tbody>
        </table>
    </div>
</div>

<div class="OrderDetails">
    
    
 
        <div id="floatHead" class="content-tab">
            <div class="content-tab-ul-wrap">
                <ul>
                    <li><a href="javascript:;" onclick="tabs(this);" class="selected">  <span id="seateName"></span></a></li>
                </ul>
            </div>
        </div> 
 

    

    <div class="line5"></div>
    <div class="tab-content1" id="Order">  
        <dl>
            <dt>		
                开台时间：
            </dt>
            <dd>   
                <span id="OrderState"></span>
            </dd> 
        </dl>
        <dl>
            <dt> 顾客人数：</dt>
            <dd>
                <span id="DineNum"></span>   
            </dd> 
        </dl>
        <dl>
            <dt>		
                合计消费：
            </dt>
            <dd>   
                ￥<span id="priceCount"></span>
            </dd> 
        </dl>
        <dl>
            <dt>		
                消费备注：
            </dt>
            <dd>   
          
            </dd> 
        </dl>  
    </div>
     <div class="line5"></div>
    <div>
        <table  width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
            <tr>
                <th>名称</th>
                <th>数量</th>
                <th>单价</th>
                <th>小计</th>
            </tr>
            <tbody id="OrderDetails"></tbody>
        </table>
    </div>
    <div class="buttonStyle" style="padding-bottom: 0;margin-bottom: 0;position: relative; top:0">
        <input type="button" value="顾客开台" id="kaitai" /> 
        @* <input type="button" value="顾客预定" id="yuding" />*@
        <input type="button" value="顾客结账" id="jiesuan"  />
    </div> 
</div>
<!--/列表-->
<!--内容底部-->
<div class="line20">
</div>
<script type="text/template" id="OrderTemp"> 
        <dl>
            <dt>		
              开台时间：
            </dt>
            <dd>   
            {{CreateTime}}
            </dd> 
        </dl>
        <dl>
            <dt> 顾客人数：</dt>
            <dd>
              {{DineNum}}人
            </dd> 
        </dl>
        <dl>
            <dt>		
              合计消费：
            </dt>
            <dd>   
             ￥<span id="priceCount"></span>
            </dd> 
        </dl>
        <dl>
            <dt>		
                 消费备注：
            </dt>
            <dd>   
           {{OrderRemark}}
            </dd> 
        </dl> 
</script>

<script type="text/template" id="OrderListTemp">
    <tr>
        <td>{{Id}}
        </td>
        <td>{{OrderState}}
        </td>
        <td>{{OrderChannel}}
        </td>
        <td>{{ContactUser}},
        </td>
        <td>{{ContactMobile}}
        </td>
        <td>bet
        </td> 
        <td>{{ReserveDate}},{{ReserveTime}}
        </td>
        <td>{{DineNum}}
        </td> 
        <td>
            <a href="javascript:;" onclick="GetOrderDetails({{Id}},{{OrderState}})">查看</a>
        </td>
    </tr>
</script>
<script type="text/template" id="OrderDetailsTemp">
    <tr>
        <td>{{CName}}</td>
        <td>{{Num}}份</td>
        <td>￥{{Price}}</td>
        <td>￥{{xiaoji}}</td>
    </tr>
</script>

